/*
 * Copyright (c) 2017, dhl and/or its affiliates. All rights reserved.
 * dhl PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
 *
 */
package com.xd.cloud.service.core;

import java.util.List;

import com.xd.cloud.dao.core.OrgUserDao;
import com.xd.cloud.entity.core.OrgUser;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.xd.cloud.dao.Page;
import com.xd.cloud.dao.core.OrgDao;
import com.xd.cloud.entity.core.Org;

/**
 * 机构service
 * 
 * @author dhl
 * @since V1.0
 * 
 */
@Service
public class OrgService {

	@Autowired
	private OrgDao orgDao;
	@Autowired
	private OrgUserDao orgUserDao;

	public int delOrg(int id) {
		return orgDao.delOrg(id);
	}

	public Org get(int id) {
		return orgDao.get(id);
	}

//	public Org getOrgByname(String name,Integer parentid) {
//		return orgDao.getOrgByname(name,parentid);
//	}

	public boolean remove(int id) {
		Org c = get(id);
		if (c != null)
		{
			orgDao.delete(c);
			return true;
		}
		else
		{
			return false;
		}
	}	

	public void update(Org c) {
		orgDao.update(c);
	}

	public List<Org> getAll() {
		return orgDao.getAll();
	}

	public List getAllOrg() {
		return orgDao.getAllOrg();
	}
	
	public Page getAllOrg(int pageNo, int pageSize) {
		return orgDao.getAllOrg(pageNo, pageSize);
	}
	
	public Object getOrg(int orgid)
	{
		return orgDao.getOrg(orgid);
	}
	
	public boolean save(Org org) {
		orgDao.save(org);
		return true;
	}	
	
	public int getChilds(int id)
	{
		return orgDao.getChilds(id);
	}

	public String getAllOrgByCurrentUserId(Integer currentUserId) {
		OrgUser orgUser = orgUserDao.getByuserid(currentUserId);
		int companyid = orgUser.getCompanyid();
		Org org = orgDao.get(companyid);

		return orgDao.getSubOrgByOrg(org);
	}

	public List<Object[]> getAllOrgByUserDataRole(String userRole) {

		return orgDao.getAllOrgByUserDataRole(userRole);
	}
}